//
//  Base.swift
//  Counter
//
//  Created by huangguojian on 2021/11/29.
//

import Foundation
import Combine
import SwiftUI

public enum SampleError: Error {
    case sampleError
}

public func check<P: Publisher>(
    _ title: String,
    publisher: () -> P
) -> AnyCancellable
{
    print("----- \(title) -----")
    defer { print("") }
    return publisher()
        .print()
        .sink(
            receiveCompletion: { _ in},
            receiveValue: { _ in }
        )
}

extension View {
    ///body 被执行时可以打印出 view 的类型：
    ///
    ///     var body: some View {
    ///         VStack { /*... */ }.debug()
    ///     }
    func debug() -> Self{
#if DEBUG
        print(Mirror(reflecting: self).subjectType)
#endif
        return self
    }
}
